package fr.vahren.sriksal.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.dao.support.DataAccessUtils;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.support.JdbcDaoSupport;

import fr.vahren.sriksal.dao.ITestDao;
import fr.vahren.sriksal.dao.bean.Message;

public class TestDao extends JdbcDaoSupport implements ITestDao {

	/*
	 * (non-Javadoc)
	 * 
	 * @see fr.vahren.sriksal.dao.impl.ITestDao#getMessage()
	 */
	@Override
	public Message getMessage() {
		Message message=null;
		message = DataAccessUtils.singleResult(getJdbcTemplate().query(
				"SELECT message FROM test WHERE id_message=1",
				new RowMapper<Message>() {

					@Override
					public Message mapRow(ResultSet rs, int i)
							throws SQLException {
						Message m = new Message();
						m.setMessage(rs.getString("message"));
						return m;
					}
				}));

		return message;
	}

}
